import axios from 'axios'
import nprogress from "nprogress"
import 'nprogress/nprogress.css'
import store from '@/store'
let instance = axios.create({
    baseURL:'/api',
    timeout:5000
})
instance.interceptors.request.use((config)=>{
    if(store.state.shopcart.userTempId){
        config.headers.userTempId = store.state.shopcart.userTempId
    }
    if(store.state.user.token){
        config.headers.token = store.state.user.token
    }
    nprogress.start();
    return config
})
instance.interceptors.response.use(
    (response)=>{
        nprogress.done();
        return response.data
    },
    (error)=>{
        Promise.reject(error)
    }
    )
export default instance;